import Vue from 'vue'
import VueRouter from 'vue-router'
import util from '@/utils/util'
import routes from './routes'
import moduleRoutes from './module-routes'

Vue.use(VueRouter)

const router = new VueRouter({
  routes: [...routes, ...moduleRoutes]
})

router.beforeEach((to, from, next) => {
  if (to.path === '/login') return next()

  if (!util.getToken()) return next('/login')

  next()
})
export default router
